module RequestHelpers

  def api_v1_expect_success(message: '', data: {})
    expect_json_types(status: :integer, message: :string, data: :object)
    return expect_json(status: 0, message: message, data: data) if message.present? && data.present?
    return expect_json(status: 0, message: message) if message.present?
    return expect_json(status: 0, data: data) if data.present?
    expect_json(status: 0)
  end

  def api_v1_expect_error(message:'', data:{})
    return expect_json(message: message, data: data) if message.present? && data.present?
    return expect_json(message: message) if message.present?
    return expect_json(data: data) if data.present?
    expect_json({ status: 400 })
  end

  def api_v1_expect_require_params
    expect_json({ status: 300, message: /必传参数/ })
  end

  def api_v1_expect_invalid_params
    expect_json({ status: 301, message: /参数不合法/ })
  end

  def api_v1_expect_login_require
    expect_json({ status: 402, message: /登录/ })
  end

  def api_v1_expect_deny_access
    expect_json({ status: 403, message: /没有权限/ })
  end

end
